package com.dude.interfaces;

import java.util.ArrayList;

import android.graphics.Bitmap;

import com.dude.objects.GenericPair;
import com.dude.objects.GenericTriplet;
import com.dude.utils.FilesOperations.FOException;

public interface IMemoryService 
{
	/** final static String variables
	 */
	// the name of the directory the data is saved in
	public static final String dirName = "myDir";
	// the name of data file for an object - first line is name of profile picture, and each 
	// consecutive line corresponds to a comment
	public static final String objectDataFileName = "objectDataFileName.txt";	
	// the name of the directory of the single objects
	public static final String singlesDirName = "singlesDir";
	// the name of the directory of the multi objects
	public static final String multiDirName = "multiDir";
	// the name of the folder of the images for each object
	public static final String imageFolderName = "imagesFolder";
	// the name of the text file where the names of all single objects comprising a single multi 
	// object appear
	public static final String innerSinglesFileName = "innerSinglesFileName";
	// a string signifying for a single object if the object doesn't use the default sound
	public static final String notUsesDefaultSoundString = "dude.com.notUsesDefaultSound";
	// a string signifying for a single object if the object uses the default sound
	public static final String usesDefaultSoundString = "dude.com.usesDefaultSound";
	// a string signifying for a single object that no path for special sound was given for this object
	public static final String noSoundPathExists = "dude.com.noSoundPathExists";
	// the width and height of an image returned as a thumbnail
	
	
		
	/**
	 * @return all application objects as pairs of values.
	 * each pair contain the name of the object and a thumbnail picture of the object 
	 * if it fails it returns null.
	 * if there are no objects in memory the returned list is empty.
	 * if an object has no image the corresponding bitmap is null. 
	 * the boolean value is true if the string is a name of a single object, else it is false. 
	 */
	public ArrayList<GenericTriplet<String, Bitmap, Boolean>> getAllObjects();
	
	
	/**
	 * @param object - a pair describing an object by name and type (the boolean value is true if
	 * the object is single and false if it multi)
	 * @return - list of the images of the object we will conduct the search upon and corresponding 
	 * path for sound (path may be null - indicates use of default sound)
	 * if it fails it returns null. if no pictures exist for the object it returns an empty list.
	 */
	public ArrayList<GenericPair<Bitmap, String>> getImagesAnrSoundsForObject(GenericPair<String, Boolean> object);


	/** method for getting the names of all objects in the file system.
	 * singleObjects and multiObjects must be valid ArrayLists at time of call. at the end of 
	 * the method, they will include the names of all single and multi objects respectively.
	 * on failure returns false.
	 */
	public boolean getAllObjectsNames(ArrayList<String> singleObjects, ArrayList<String> multiObjects);
	
	
	/** the method returns true if no single object with name "name" already exists in memory,
	 *  else it returns false
	 */
	public boolean isNameFreeForSingleObject(String name);
	
	
	/** the method returns true if no multi object with name "name" already exists in memory,
	 *  else it returns false
	 */
	public boolean isNameFreeForMultiObject(String name);
	
	
	/** the method renames the multi object called oldName to newName. it assumes such object
	 * exists at the time of the call to the method. 
	 * if it succeeds it returns true, else it returns false.
	 */
	public boolean renameMultiObject(String oldName, String newName);
	
	
	/** the method renames the single object called oldName to newName. it assumes such object
	 * exists at the time of the call to the method. 
	 * if it succeeds it returns true, else it returns false.
	 */
	public boolean renameSingleObject(String oldName, String newName);
	

	/** the method returns an ArrayList with all the comments for the specified object.
	 * if it fails, it returns null.
	 */
	public ArrayList<String> getAllCommentsForObject(String objName, boolean isSingle);
	
	
	/** the method adds a comment to the comments' file of the given object.
	 * if it fails or there is no object with the given name in the system, it returns false.
	 */
	public boolean addCommentForObject(String objName, boolean isSingle, String comment);
	
	
	/** the method removes the comment from the comments' file of the given object.
	 * if it fails it returns false.
	 */
	public boolean removeComment(String objName, boolean isSingle, String comment);
	
	
	/** the method returns the width and height parameter used in ThumbnailUtils.extractThumbnail
	 * to return a thumnbnail of an image
	 */
	public int getThumbnailSize();
	
	
	/** the method sets the width and height parameter used in ThumbnailUtils.extractThumbnail
	 * to return a thumnbnail of an image
	 */
	public void setThumbnailSize(int s);
	
	
	/** the method saves pic as a picture for the single object with name objName.
	 * if this is the first picture added to the object, then it is automatically the profile picture.
	 * it assumes the object doesn't yet have the maximum number of pictures allowed, and that
	 * objName is a valid object name.
	 * if it succeeds it returns the name of the new image, else it returns null.
	 */
	public String addImage(String objName, Bitmap pic);
	
	
	/** the method copies the image at the given path to the object's folder.
	 * if it fails it returns null, else it returns the image's name
	 */
	public String addPictureFromPath(String objName, String path);
	
	
	/** the method returns true of the single object already has the maximum allowed number of 
	 * pictures, as defined by a constant. else it returns false. 
	 * $pre: objName represents a valid object name
	 */
	public boolean hasMaxNumOfPictures(String objName);
	
	
	/** the method returns a GenricPair comprising of the name of the profile's picture  and a 
	 * Bitmap of that picture, of the single object named objName, if such exists.
	 * if no such picture exists it returns null.	
	 * if (minimize==true) it sub-samples the picture and returns a thumbnail
	 * it assumes objName is valid name. 
	 * upon failure it throws FOException. 
	 * the profile picture is the one whose name appears in first line in data file
	 */
	public GenericPair<String, Bitmap> getProfileImage(String objName, boolean minimize) throws FOException;
	
	
	
	/** the method changes the name of a picture belonging to object objName.
	 * the picture named oldPicName is renamed newPicName
	 * if the method fails it returns 3, if another picture with this name already exists
	 * it returns 2 (and doesn't do the rename), if it succeeds it returns 1.
	 * oldPicName and newPicName without ending .jpg
	 */
	public int renamePicture(String objName, String oldPicName, String newPicName);
	
	
	
	/** the method returns all an array of all the pictures+names of the single object with name 
	 * objName. 
	 * if (minimize==true) it sub-samples the picture and returns a thumbnail
	 * it assumes objName is a valid name of an existing object.
	 */
	public ArrayList<GenericPair<String,Bitmap>> getAllPictures(String objName, boolean minimize);
	
	
	/** remove the picture with name picName from the pictures saved for the single object.
	 * it assumes objName and picName are valid. if the picture is the profile's picture, a different
	 * picture is chosen for the profile (if another one exists for the object)
	 * if it fails it returns false.
	 * picName - without ending.jpg
	 */
	public boolean removeImage(String objName, String picName);
	
	
	
	/** the method adds a new object by the name objName to the file system.
	 * if ($ret==1) then operation succeeded. if ($ret==2) then object by the same name
	 *  already exists and operation aborted. if ($ret==3) then operation failed
	 */
	public int addObject(String objName, boolean isSingle);
	
	
	/** the method deletes the object with the name objName and all associated data from the 
	 * file system. if it fails it returns false.
	 */
	public boolean removeObject(String objName, boolean isSingle);
	
	
	
	
	/** the method adds objName as a single object included in the multi object.
	 * it assumes that multiName and objName are valid names of a multi and a single object
	 * respectively.
	 * if it fails it returns false.
	 * if object is already a part of multi object it returns true, and doesn't add it again.
	 */
	public boolean addObjectToMultiObject(String multiName, String objName);
	
	
	
	/** this method removes objName from the multi object denoted by multiName. 
	 * it assumes both names are valid objects' names.
	 * if it fails it returns false.
	 */
	public boolean removeObjectFromMultiObject(String multiName, String objName);
	
	
	/** the method returns an array with the names of all multi or single objects in the memory,
	 * depending on whether singles==false or singles==true
	 * if the method fails it returns null
	 */
	public String [] getOneTypeObjectsNames(boolean singles);
	
	
	
	/** the method returns a list of all single objects' names and pictures that who are included
	 * in the given multi object.
	 * it assumes multiName is a valid multi object's name. 
	 * if it fails it returns null
	 */
	public  ArrayList<GenericPair<String, Bitmap>> getAllIncludedObjects(String multiName);
	
	
	
	/** the method returns true if the single object represented by objName uses the default sound
	 * and false otherwise. it assumes the object exists.
	 * return int - 1 for uses default, 2 for not uses default, 3 for failure
	 */
	public int getUsesDefaultSound(String objName);
	
	
	
	/** the method sets whether the single object represented by objName uses the default sound.
	 * it returns false if it failed.
	 */
	public boolean setUsesDefaultSound(String objName, boolean usesDefault);
	
	
	/** the method returns a string representing the path of the sound associated with the single
	 * object named objName. if it fails it returns null.
	 * -- the method should only be called if objectHasSound(objName)==true
	 */
	public String getSoundPath(String objName);
	
	
	/** the method returns true if the single object with the name objName has a sound. 
	 * else it returns false. it assumes the object's name is valid.
	 */
	public boolean objectHasSound(String objName);
	
	
	/** the method sets path as the path of the sound associated with objname. if the object already 
	 * had a sound, the new path overrides it.
	 * if it fails it returns false.
	 */
	public boolean setSoundPath(String objName, String path);
	
	
	/** the method deletes all single objects from memory. if it fails it returns false.
	 */
	public boolean deleteAllSingleObjects();
	
	
	/**  the method deletes all multi objects from memory. if it fails it returns false.
	 */
	public boolean deleteAllMultiObjects();
	
		
	
	/** the method creates all the main directories of the application, and returns false
	 * if it fails
	 */
	public boolean initializeDirectory();
	
	
	
	
	
	
}
